package com.fivestar.pmanager.service;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fivestar.pmanager.core.base.BaseCommonParameterBean;
import com.fivestar.pmanager.core.exception.DMLNoRecordEffectedException;
import com.fivestar.pmanager.core.service.BaseServiceImpl;
import com.fivestar.pmanager.dao.mapper.SysModuleMapper;
import com.fivestar.pmanager.model.SysModuleBean;


 /**
 * 模块
 * SmModuleService
 * @author 
 */
@Service("sysModuleService")
public class SysModuleService extends BaseServiceImpl<SysModuleBean>
{
	private final static Logger log = Logger.getLogger(SysModuleService.class);
	@Autowired
    private SysModuleMapper mapper;


    @Override
    public int insert(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysModuleBean.initBeforeCreate(commonParam.getActorId());
        int result;
        if ((result = mapper.insert(sysModuleBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int delete(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysModuleBean.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.delete(sysModuleBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }

    @Override
    public int deletePhysics(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException {
        int result;
        if ((result = mapper.deletePhysics(sysModuleBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int update(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysModuleBean.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.update(sysModuleBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }
    
    
    @Override
    public int updateBySelective(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysModuleBean.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.updateBySelective(sysModuleBean)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public List<SysModuleBean> getList(SysModuleBean sysModuleBean)
    {
        return mapper.getList(sysModuleBean);
    }


    @Override
    public SysModuleBean getSingleById(Integer id)
    {
        return mapper.getSingleById(id);
    }


    @Override
    public int getCountOfPage(SysModuleBean sysModuleBean)
    {
        return mapper.getCountOfPage(sysModuleBean);
    }


    @Override
    public List<SysModuleBean> getListOfPage(SysModuleBean sysModuleBean)
    {
        return mapper.getListOfPage(sysModuleBean);
    }


	@Override
    public int getCount(SysModuleBean sysModuleBean)
    {
        return mapper.getCount(sysModuleBean);
    }


    @Override
    public void save(SysModuleBean sysModuleBean, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        if(sysModuleBean.getRowId() == null)
        {
            insert(sysModuleBean, commonParam);
        }
        else
        {
            updateBySelective(sysModuleBean, commonParam);
        }
    }


    @Override
    public SysModuleBean getSingle(SysModuleBean sysModuleBean)
    {
        return mapper.getSingle(sysModuleBean);
    }

    /**
     * 获取用户模块
     *
     * @param userId
     * @return List<SysModuleBean>
     */
    public List<SysModuleBean> getUserModule(int userId)
    {
        return  mapper.getUserModule(userId);
    }
    
    /**
     * 根据父id查询子菜单列表
     * @param pid
     * @return
     */
    public List<SysModuleBean> queryModuleByPid(String pid){
    	return mapper.queryModuleByPid(pid);
    }

    /**
     * 查询角色 模块列表
     * @param roleId
     * @return
     */
    public List<SysModuleBean> queryRoleModuleByRoleId(Map<String,Object> map){
    	return mapper.queryRoleModuleByRoleId(map);
    }
}
